package per.hnvcam.searchext.data.dao.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import per.hnvcam.searchext.data.dao.WebReferenceDAO;
import per.hnvcam.searchext.data.model.WebReference;

@Service("WebReferenceDAO")
@Transactional
public class WebReferenceDAOImpl extends BaseDAOImpl implements WebReferenceDAO {

   @SuppressWarnings({ "rawtypes", "unchecked" })
   @Override
   public List listPages() {
      return getHibernateTemplate().find("from WebReference");
   }

   @Override
   public void savePage(WebReference newPage) {
      getHibernateTemplate().save(newPage);
   }

   @Override
   public void updatePage(WebReference updatedPage) {
      getHibernateTemplate().update(updatedPage);
   }

   @Override
   public WebReference findById(long id) {
      @SuppressWarnings("rawtypes")
      List result = getHibernateTemplate().find("from WebReference webRef where webRef.id = ?", id);
      if (result != null && result.size() > 0) {
         return (WebReference) result.get(0);
      }
      return null;
   }

   @Override
   public List findByUrl(String url) {
      return getHibernateTemplate().find("from WebReference webRef where webRef.url = ?", url);
   }
}
